home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / pray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  41.3 KB  |  1,455 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)pray.c    3.1    93/04/24    */
  2. /* Copyright (c) Benson I. Margulies, Mike Stephenson, Steve Linhart, 1989. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #include "epri.h"
  7.  
  8. STATIC_PTR int NDECL(prayer_done);
  9. static int NDECL(in_trouble);
  10. static void FDECL(fix_worst_trouble,(int));
  11. static void FDECL(angrygods,(ALIGNTYP_P));
  12. static void FDECL(pleased,(ALIGNTYP_P));
  13. static void FDECL(godvoice,(ALIGNTYP_P,const char*));
  14. static void FDECL(god_zaps_you,(ALIGNTYP_P));
  15. static void FDECL(gods_angry,(ALIGNTYP_P));
  16. static void FDECL(gods_upset,(ALIGNTYP_P));
  17. static void FDECL(consume_offering,(struct obj *));
  18. static boolean FDECL(water_prayer,(BOOLEAN_P));
  19.  
  20. /*
  21.  * Logic behind deities and altars and such:
  22.  * + prayers are made to your god if not on an altar, and to the altar's god
  23.  *   if you are on an altar
  24.  * + If possible, your god answers all prayers, which is why bad things happen
  25.  *   if you try to pray on another god's altar
  26.  * + sacrifices work basically the same way, but the other god may decide to
  27.  *   accept your allegiance, after which they are your god.  If rejected,
  28.  *   your god takes over with your punishment.
  29.  * + if you're in Gehennom, all messages come from the chaotic god
  30.  */
  31. static
  32. struct ghods {
  33.     char    classlet;
  34.     const char *law, *balance, *chaos;
  35. }  gods[] = {
  36. {'A', /* Central American */    "Quetzalcoatl", "Camaxtli", "Huhetotl"},
  37. {'B', /* Hyborian */        "Mitra", "Crom", "Set"},
  38. {'C', /* Babylonian */        "Anu", "Ishtar", "Anshar"},
  39. {'E', /* Elven */        "Solonor Thelandira",
  40.                     "Aerdrie Faenya", "Erevan Ilesere"},
  41. {'H', /* Greek */        "Athena", "Hermes", "Poseidon"},
  42. {'K', /* Celtic */        "Lugh", "Brigit", "Macannan Mac Lir"},
  43. {'P', /* Chinese */        "Shan Lai Ching", "Chih Sung-tzu", "Huan Ti"},
  44. {'R', /* Nehwon */        "Issek", "Mog", "Kos"},
  45. {'S', /* Japanese */        "Amaterasu Omikami", "Raiden", "Susanowo"},
  46. #ifdef TOURIST
  47. {'T', /* Discworld */        "Blind Io", "The Lady", "Offler"},
  48. #endif
  49. {'V', /* Norse */        "Tyr", "Odin", "Loki"},
  50. {'W', /* Egyptian */        "Ptah", "Thoth", "Anhur"},
  51. {0,0,0,0}
  52. };
  53.  
  54. /*
  55.  *    Moloch, who dwells in Gehennom, is the "renegade" cruel god
  56.  *    responsible for the theft of the Amulet from Marduk, the Creator.
  57.  *    Moloch is unaligned.
  58.  */
  59. static const char    *Moloch = "Moloch";
  60.  
  61. static const char *godvoices[] = {
  62.     "booms out",
  63.     "thunders",
  64.     "rings out",
  65.     "booms",
  66. };
  67.  
  68. /* values calculated when prayer starts, and used when completed */
  69. static aligntyp p_aligntyp;
  70. static int p_trouble;
  71. static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
  72.  
  73. #define PIOUS 20
  74. #define DEVOUT 14
  75. #define FERVENT 9
  76. #define STRIDENT 4
  77.  
  78. #define TROUBLE_STONED 10
  79. #define TROUBLE_STRANGLED 9
  80. #define TROUBLE_LAVA 8
  81. #define TROUBLE_SICK 7
  82. #define TROUBLE_STARVING 6
  83. #define TROUBLE_HIT 5
  84. #define TROUBLE_LYCANTHROPE 4
  85. #define TROUBLE_STUCK_IN_WALL 3
  86. #define TROUBLE_CURSED_BLINDFOLD 2
  87. #define TROUBLE_CURSED_LEVITATION 1
  88.  
  89. #define TROUBLE_PUNISHED (-1)
  90. #define TROUBLE_CURSED_ITEMS (-2)
  91. #define TROUBLE_BLIND (-3)
  92. #define TROUBLE_HUNGRY (-4)
  93. #define TROUBLE_POISONED (-5)
  94. #define TROUBLE_WOUNDED_LEGS (-6)
  95. #define TROUBLE_STUNNED (-7)
  96. #define TROUBLE_CONFUSED (-8)
  97. #define TROUBLE_HALLUCINATION (-9)
  98.  
  99. /* We could force rehumanize of polyselfed people, but we can't tell
  100.    unintentional shape changes from the other kind. Oh well. */
  101.  
  102. /* Return 0 if nothing particular seems wrong, positive numbers for
  103.    serious trouble, and negative numbers for comparative annoyances. This
  104.    returns the worst problem. There may be others, and the gods may fix
  105.    more than one.
  106.  
  107. This could get as bizarre as noting surrounding opponents, (or hostile dogs),
  108. but that's really hard.
  109.  */
  110.  
  111. #define ugod_is_angry() (u.ualign.record < 0)
  112. #define on_altar()    IS_ALTAR(levl[u.ux][u.uy].typ)
  113. #define on_shrine()    ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0)
  114. #define a_align(x,y)    ((aligntyp)Amask2align(levl[x][y].altarmask & ~AM_SHRINE))
  115.  
  116. static int
  117. in_trouble()
  118. {
  119.     register struct obj *otmp;
  120.     int i, j, count=0;
  121.  
  122. /* Borrowed from eat.c */
  123.  
  124. #define    SATIATED    0
  125. #define NOT_HUNGRY    1
  126. #define    HUNGRY        2
  127. #define    WEAK        3
  128. #define    FAINTING    4
  129. #define FAINTED        5
  130. #define STARVED        6
  131.  
  132.     if(Stoned) return(TROUBLE_STONED);
  133.     if(Strangled) return(TROUBLE_STRANGLED);
  134.     if(u.utrap && u.utraptype == TT_LAVA) return(TROUBLE_LAVA);
  135.     if(Sick) return(TROUBLE_SICK);
  136.     if(u.uhs >= WEAK) return(TROUBLE_STARVING);
  137.     if(u.uhp < 5 || (u.uhp*7 < u.uhpmax)) return(TROUBLE_HIT);
  138. #ifdef POLYSELF
  139.     if(u.ulycn >= 0) return(TROUBLE_LYCANTHROPE);
  140. #endif
  141.     for (i= -1; i<=1; i++) for(j= -1; j<=1; j++) {
  142.         if (!i && !j) continue;
  143.         if (!isok(u.ux+i, u.uy+j) || IS_ROCK(levl[u.ux+i][u.uy+j].typ))
  144.             count++;
  145.     }
  146.     if(count==8
  147. #ifdef POLYSELF
  148.         && !passes_walls(uasmon)
  149. #endif
  150.         ) return(TROUBLE_STUCK_IN_WALL);
  151.     if((uarmf && uarmf->otyp==LEVITATION_BOOTS && uarmf->cursed) ||
  152.         (uleft && uleft->otyp==RIN_LEVITATION && uleft->cursed) ||
  153.         (uright && uright->otyp==RIN_LEVITATION && uright->cursed))
  154.         return(TROUBLE_CURSED_LEVITATION);
  155.     if(ublindf && ublindf->cursed) return(TROUBLE_CURSED_BLINDFOLD);
  156.  
  157.     if(Punished) return(TROUBLE_PUNISHED);
  158.     for(otmp=invent; otmp; otmp=otmp->nobj)
  159.         if((otmp->otyp==LOADSTONE || otmp->otyp==LUCKSTONE) &&
  160.             otmp->cursed)
  161.             return(TROUBLE_CURSED_ITEMS);
  162.     if((uarmh && uarmh->cursed) ||    /* helmet */
  163.        (uarms && uarms->cursed) ||    /* shield */
  164.        (uarmg && uarmg->cursed) ||    /* gloves */
  165.        (uarm && uarm->cursed) ||    /* armor */
  166.        (uarmc && uarmc->cursed) ||    /* cloak */
  167.        (uarmf && uarmf->cursed && uarmf->otyp != LEVITATION_BOOTS) ||
  168.                     /* boots */
  169. #ifdef TOURIST
  170.        (uarmu && uarmu->cursed) ||  /* shirt */
  171. #endif
  172.        (welded(uwep)) ||
  173.        (uleft && uleft->cursed && uleft->otyp != RIN_LEVITATION) ||
  174.        (uright && uright->cursed && uright->otyp != RIN_LEVITATION) ||
  175.        (uamul && uamul->cursed))
  176.  
  177.        return(TROUBLE_CURSED_ITEMS);
  178.  
  179.     if(Blinded > 1) return(TROUBLE_BLIND);
  180.     if(u.uhs >= HUNGRY) return(TROUBLE_HUNGRY);
  181.     for(i=0; i<A_MAX; i++)
  182.         if(ABASE(i) < AMAX(i)) return(TROUBLE_POISONED);
  183.     if(Wounded_legs) return (TROUBLE_WOUNDED_LEGS);
  184.     if(HStun) return (TROUBLE_STUNNED);
  185.     if(HConfusion) return (TROUBLE_CONFUSED);
  186.     if(Hallucination) return(TROUBLE_HALLUCINATION);
  187.  
  188.     return(0);
  189. }
  190.  
  191. const char leftglow[] = "left ring softly glows";
  192. const char rightglow[] = "right ring softly glows";
  193.  
  194. static void
  195. fix_worst_trouble(trouble)
  196. register int trouble;
  197. {
  198.     int i;
  199.     struct obj *otmp;
  200.     const char *what = NULL;
  201.  
  202.     u.ublesscnt += rnz(100);
  203.     switch (trouble) {
  204.         case TROUBLE_STONED:
  205.             You("feel more limber.");
  206.             Stoned = 0;
  207.             break;
  208.         case TROUBLE_STRANGLED:
  209.             You("can breathe again.");
  210.             Strangled = 0;
  211.             break;
  212.         case TROUBLE_LAVA:
  213.             You("are back on solid ground.");
  214.             /* teleport should always succeed, but if not,
  215.              * just untrap them.
  216.              */
  217.             if(!safe_teleds())
  218.             u.utrap = 0;
  219.             break;
  220.         case TROUBLE_STARVING:
  221.             losestr(-1);
  222.             /* fall into... */
  223.         case TROUBLE_HUNGRY:
  224.             Your("stomach feels content.");
  225.             init_uhunger ();
  226.             flags.botl = 1;
  227.             break;
  228.         case TROUBLE_SICK:
  229.             You("feel better.");
  230.             make_sick(0L,FALSE);
  231.             break;
  232.         case TROUBLE_HIT:
  233.             You("feel much better.");
  234.             if (u.uhpmax < u.ulevel * 5 + 11)
  235.             u.uhp = u.uhpmax += rnd(5);
  236.             else
  237.             u.uhp = u.uhpmax;
  238.             flags.botl = 1;
  239.             break;
  240.         case TROUBLE_STUCK_IN_WALL:
  241.             Your("surroundings change.");
  242.             tele();
  243.             break;
  244.         case TROUBLE_CURSED_LEVITATION:
  245.             if (uarmf && uarmf->otyp==LEVITATION_BOOTS
  246.                         && uarmf->cursed)
  247.             otmp = uarmf;
  248.             else if (uleft && uleft->otyp==RIN_LEVITATION
  249.                         && uleft->cursed) {
  250.             otmp = uleft;
  251.             what = leftglow;
  252.             } else {
  253.             otmp = uright;
  254.             what = rightglow;
  255.             }
  256.             goto decurse;
  257.         case TROUBLE_CURSED_BLINDFOLD:
  258.             otmp = ublindf;
  259.             goto decurse;
  260.         case TROUBLE_PUNISHED:
  261.             Your("chain disappears.");
  262.             unpunish();
  263.             break;
  264. #ifdef POLYSELF
  265.         case TROUBLE_LYCANTHROPE:
  266.             You("feel purified.");
  267.             if(uasmon == &mons[u.ulycn] && !Polymorph_control)
  268.             rehumanize();
  269.             u.ulycn = -1;       /* now remove the curse */
  270.             break;
  271. #endif
  272.         case TROUBLE_CURSED_ITEMS:
  273.             if (uarmh && uarmh->cursed)        /* helmet */
  274.                 otmp = uarmh;
  275.             else if (uarms && uarms->cursed)    /* shield */
  276.                 otmp = uarms;
  277.             else if (uarmg && uarmg->cursed)    /* gloves */
  278.                 otmp = uarmg;
  279.             else if (uarm && uarm->cursed)    /* armor */
  280.                 otmp = uarm;
  281.             else if (uarmc && uarmc->cursed)    /* cloak */
  282.                 otmp = uarmc;
  283.             else if (uarmf && uarmf->cursed)    /* boots */
  284.                 otmp = uarmf;
  285. #ifdef TOURIST
  286.             else if (uarmu && uarmu->cursed)    /* shirt */
  287.                 otmp = uarmu;
  288. #endif
  289.             else if (uleft && uleft->cursed) {
  290.                 otmp = uleft;
  291.                 what = leftglow;
  292.             } else if (uright && uright->cursed) {
  293.                 otmp = uright;
  294.                 what = rightglow;
  295.             } else if (uamul && uamul->cursed) /* amulet */
  296.                 otmp = uamul;
  297.             else if (welded(uwep)) otmp = uwep;
  298.             else {
  299.                 for(otmp=invent; otmp; otmp=otmp->nobj)
  300.                 if ((otmp->otyp==LOADSTONE ||
  301.                      otmp->otyp==LUCKSTONE) && otmp->cursed)
  302.                     break;
  303.             }
  304. decurse:
  305.             uncurse(otmp);
  306.             otmp->bknown = TRUE;
  307.             if (!Blind)
  308.                 Your("%s %s.",
  309.                  what ? what :
  310.                  (const char *)aobjnam (otmp, "softly glow"),
  311.                  Hallucination ? hcolor() : amber);
  312.             break;
  313.         case TROUBLE_HALLUCINATION:
  314.             pline ("Looks like you are back in Kansas.");
  315.             make_hallucinated(0L,FALSE,0L);
  316.             break;
  317.         case TROUBLE_BLIND:
  318.             Your("%s feel better.", makeplural(body_part(EYE)));
  319.             make_blinded(0L,FALSE);
  320.             break;
  321.         case TROUBLE_POISONED:
  322.             if (Hallucination)
  323.             pline("There's a tiger in your tank.");
  324.             else
  325.             You("feel in good health again.");
  326.             for(i=0; i<A_MAX; i++) {
  327.             if(ABASE(i) < AMAX(i)) {
  328.                 ABASE(i) = AMAX(i);
  329.                 flags.botl = 1;
  330.             }
  331.             }
  332.             break;
  333.         case TROUBLE_WOUNDED_LEGS:
  334.             heal_legs();
  335.             break;
  336.         case TROUBLE_STUNNED:
  337.             make_stunned(0L,TRUE);
  338.             break;
  339.         case TROUBLE_CONFUSED:
  340.             make_confused(0L,TRUE);
  341.             break;
  342.     }
  343. }
  344.  
  345. static void
  346. god_zaps_you(resp_god)
  347. aligntyp resp_god;
  348. {
  349.     pline("Suddenly, a bolt of lightning strikes you!");
  350.     if (Reflecting) {
  351.         shieldeff(u.ux, u.uy);
  352.         if (Blind)
  353.         pline("For some reason you're unaffected.");
  354.         else {
  355.         if (Reflecting & W_AMUL) {
  356.             pline("It reflects from your medallion.");
  357.             makeknown(AMULET_OF_REFLECTION);
  358.         } else {
  359.             pline("It reflects from your shield.");
  360.             makeknown(SHIELD_OF_REFLECTION);
  361.         }
  362.         }
  363.         goto ohno;
  364.     } else if (Shock_resistance) {
  365.         shieldeff(u.ux, u.uy);
  366.         pline("It seems not to affect you.");
  367. ohno:
  368.         pline("%s is not deterred...", align_gname(resp_god));
  369.         pline("A wide-angle disintegration beam hits you!");
  370.         if (Disint_resistance) {
  371.         You("bask in its %s glow for a minute...", Black);
  372.         godvoice(resp_god, "I believe it not!");
  373.         if(Is_astralevel(&u.uz)) {
  374.  
  375.             /* one more try on the astral level */
  376.             verbalize("Thou cannot escape my wrath, mortal!");
  377.             summon_minion(resp_god, FALSE);
  378.             summon_minion(resp_god, FALSE);
  379.             summon_minion(resp_god, FALSE);
  380.             verbalize("Destroy %s, my servants!", him[flags.female]);
  381.         }
  382.         return;
  383.         }
  384.     }
  385.     {
  386.         char killerbuf[64];
  387.         You("fry to a crisp.");
  388.         killer_format = KILLED_BY;
  389.         Sprintf(killerbuf, "the wrath of %s", align_gname(resp_god));
  390.         killer = killerbuf;
  391.         done(DIED);
  392.     }
  393. }
  394.  
  395. static void
  396. angrygods(resp_god)
  397. aligntyp resp_god;
  398. {
  399.     register int    maxanger;
  400.  
  401.     if(Inhell) resp_god = A_NONE;
  402.     u.ublessed = 0;
  403.  
  404.     /* changed from tmp = u.ugangr + abs (u.uluck) -- rph */
  405.     /* added test for alignment diff -dlc */
  406.     if(resp_god != u.ualign.type)
  407.         maxanger =  u.ualign.record/2 + (Luck > 0 ? -Luck/3 : -Luck);
  408.     else
  409.         maxanger =  3*u.ugangr +
  410.         ((Luck > 0 || u.ualign.record >= STRIDENT) ? -Luck/3 : -Luck);
  411.     if (maxanger < 0) maxanger = 0; /* possible if bad align & good luck */
  412.     maxanger =  (maxanger > 15 ? 15 : maxanger);  /* be reasonable */
  413.     switch (maxanger ? rn2(maxanger): 0) {
  414.  
  415.         case 0:
  416.         case 1:    You("feel that %s is %s.", align_gname(resp_god),
  417.                 Hallucination ? "bummed" : "displeased");
  418.             break;
  419.         case 2:
  420.         case 3:
  421.             godvoice(resp_god,NULL);
  422. # ifdef POLYSELF
  423.             pline("\"Thou %s, %s.\"",
  424.                   ugod_is_angry() ? "hast strayed from the path" :
  425.                         "art arrogant",
  426.                   u.usym == S_HUMAN ? "mortal" : "creature");
  427. # else
  428.             pline("\"Thou %s, mortal.\"",
  429.                   ugod_is_angry() ? "hast strayed from the path" :
  430.                         "art arrogant");
  431. # endif
  432.             verbalize("Thou must relearn thy lessons!");
  433.             (void) adjattrib(A_WIS, -1, FALSE);
  434.             if (u.ulevel > 1) {
  435.                 losexp();
  436.                 if(u.uhp < 1) u.uhp = 1;
  437.                 if(u.uhpmax < 1) u.uhpmax = 1;
  438.             } else  {
  439.                 u.uexp = 0;
  440.                 flags.botl = 1;
  441.             }
  442.             break;
  443.         case 6:    if (!Punished) {
  444.                 gods_angry(resp_god);
  445.                 punish((struct obj *)0);
  446.                 break;
  447.             } /* else fall thru */
  448.         case 4:
  449.         case 5:    gods_angry(resp_god);
  450.             if (!Blind && !Antimagic)
  451.                 pline("%s glow surrounds you.",
  452.                   An(Hallucination ? hcolor() : Black));
  453.             rndcurse();
  454.             break;
  455.         case 7:
  456.         case 8:    godvoice(resp_god,NULL);
  457.             verbalize("Thou durst %s me?",
  458.                   (on_altar() &&
  459.                    (a_align(u.ux,u.uy) != resp_god)) ?
  460.                   "scorn":"call upon");
  461. # ifdef POLYSELF
  462.             pline("\"Then die, %s!\"",
  463.                   u.usym == S_HUMAN ? "mortal" : "creature");
  464. # else
  465.             verbalize("Then die, mortal!");
  466. # endif
  467.  
  468.             summon_minion(resp_god, FALSE);
  469.             break;
  470.  
  471.         default:    gods_angry(resp_god);
  472.             god_zaps_you(resp_god);
  473.             break;
  474.     }
  475.     u.ublesscnt = rnz(300);
  476.     return;
  477. }
  478.  
  479. static void
  480. pleased(g_align)
  481.     aligntyp g_align;
  482. {
  483.     int trouble = p_trouble;    /* what's your worst difficulty? */
  484.     int pat_on_head = 0;
  485.  
  486.     You("feel that %s is %s.", align_gname(g_align),
  487.         u.ualign.record >= DEVOUT ?
  488.         Hallucination ? "pleased as punch" : "well-pleased" :
  489.         u.ualign.record >= STRIDENT ?
  490.         Hallucination ? "ticklish" : "pleased" :
  491.         Hallucination ? "full" : "satisfied");
  492.  
  493.     /* not your deity */
  494.     if (on_altar() && p_aligntyp != u.ualign.type) {
  495.         adjalign(-1);
  496.         return;
  497.     } else if (u.ualign.record < 2) adjalign(1);
  498.  
  499.     /* depending on your luck & align level, the god you prayed to will:
  500.        - fix your worst problem if it's major.
  501.        - fix all your major problems.
  502.        - fix your worst problem if it's minor.
  503.        - fix all of your problems.
  504.        - do you a gratuitous favor.
  505.  
  506.        if you make it to the the last category, you roll randomly again
  507.        to see what they do for you.
  508.  
  509.        If your luck is at least 0, then you are guaranteed rescued
  510.        from your worst major problem. */
  511.  
  512.     if (!trouble && u.ualign.record >= DEVOUT) pat_on_head = 1;
  513.     else {
  514.         int action = rn1(on_altar() ? 3 + on_shrine() : 2, Luck+1);
  515.  
  516.         if (!on_altar()) action = max(action,2);
  517.         if (u.ualign.record < STRIDENT)
  518.         action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0;
  519.  
  520.         switch(min(action,5)) {
  521.         case 5: pat_on_head = 1;
  522.         case 4: do fix_worst_trouble(trouble);
  523.             while ((trouble = in_trouble()) != 0);
  524.             break;
  525.  
  526.         case 3: fix_worst_trouble(trouble);
  527.         case 2: while ((trouble = in_trouble()) > 0)
  528.             fix_worst_trouble(trouble);
  529.             break;
  530.  
  531.         case 1: if (trouble > 0) fix_worst_trouble(trouble);
  532.         case 0: break; /* your god blows you off, too bad */
  533.         }
  534.     }
  535.  
  536.     if(pat_on_head)
  537.     switch(rn2((Luck + 6)>>1)) {
  538.     case 0:    break;
  539.     case 1:
  540.         if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS ||
  541.              uwep->otyp == PICK_AXE || uwep->otyp == UNICORN_HORN)
  542.                 && (!uwep->blessed)) {
  543.         if (uwep->cursed) {
  544.             uwep->cursed = FALSE;
  545.             uwep->bknown = TRUE;
  546.             if (!Blind)
  547.             Your("%s %s.", aobjnam(uwep, "softly glow"),
  548.                  Hallucination ? hcolor() : amber);
  549.             else You("feel the power of %s over your %s.",
  550.             u_gname(), xname(uwep));
  551.         } else if(uwep->otyp < BOW || uwep->otyp > CROSSBOW) {
  552.             uwep->blessed = uwep->bknown = TRUE;
  553.             if (!Blind)
  554.             Your("%s with %s aura.",
  555.                  aobjnam(uwep, "softly glow"),
  556.                  an(Hallucination ? hcolor() : light_blue));
  557.             else You("feel the blessing of %s over your %s.",
  558.             u_gname(), xname(uwep));
  559.         }
  560.         }
  561.         break;
  562.     case 3:
  563.         /* takes 2 hints to get the music to enter the stronghold */
  564.         if (flags.soundok && !u.uevent.uopened_dbridge) {
  565.         if(u.uevent.uheard_tune < 1) {
  566.             godvoice(g_align,NULL);
  567. #ifdef POLYSELF
  568.             verbalize("Hark, %s!",
  569.               u.usym == S_HUMAN ? "mortal" : "creature");
  570. #else
  571.             verbalize("Hark, mortal!");
  572. #endif
  573.             verbalize(
  574.             "To enter the castle, thou must play the right tune!");
  575.             u.uevent.uheard_tune++;
  576.             break;
  577.         } else if (u.uevent.uheard_tune < 2) {
  578.             You(Hallucination ? "hear a funeral march..." : "hear a divine music...");
  579.             pline("It sounds like:  \"%s\".", tune);
  580.             u.uevent.uheard_tune++;
  581.             break;
  582.         }
  583.         }
  584.         /* Otherwise, falls into next case */
  585.     case 2:
  586.         if (!Blind)
  587.         You("are surrounded by %s glow.",
  588.             an(Hallucination ? hcolor() : golden));
  589.         u.uhp = u.uhpmax += 5;
  590.         ABASE(A_STR) = AMAX(A_STR);
  591.         if (u.uhunger < 900)    init_uhunger();
  592.         if (u.uluck < 0)    u.uluck = 0;
  593.         make_blinded(0L,TRUE);
  594.         flags.botl = 1;
  595.         break;
  596.     case 4: {
  597.         register struct obj *otmp;
  598.  
  599.         if (Blind)
  600.         You("feel the power of %s.", u_gname());
  601.         else You("are surrounded by %s aura.",
  602.              an(Hallucination ? hcolor() : light_blue));
  603.         for(otmp=invent; otmp; otmp=otmp->nobj) {
  604.         if (otmp->cursed) {
  605.             uncurse(otmp);
  606.             if (!Blind) {
  607.             Your("%s %s.", aobjnam(otmp, "softly glow"),
  608.                  Hallucination ? hcolor() : amber);
  609.             otmp->bknown = TRUE;
  610.             }
  611.         }
  612.         }
  613.         break;
  614.     }
  615.     case 5: {
  616.         const char *msg="\"and thus I grant thee the gift of %s!\"";
  617.         godvoice(u.ualign.type, "Thou hast pleased me with thy progress,");
  618.         if (!(HTelepat & INTRINSIC))  {
  619.         HTelepat |= FROMOUTSIDE;
  620.         pline(msg, "Telepathy");
  621.         if (Blind) see_monsters();
  622.         } else if (!(Fast & INTRINSIC))  {
  623.         Fast |= FROMOUTSIDE;
  624.         pline(msg, "Speed");
  625.         } else if (!(Stealth & INTRINSIC))  {
  626.         Stealth |= FROMOUTSIDE;
  627.         pline(msg, "Stealth");
  628.         } else {
  629.         if (!(Protection & INTRINSIC))  {
  630.             Protection |= FROMOUTSIDE;
  631.             if (!u.ublessed)  u.ublessed = rn1(3, 2);
  632.         } else u.ublessed++;
  633.         pline(msg, "my protection");
  634.         }
  635.         verbalize("Use it wisely in my name!");
  636.         break;
  637.     }
  638.     case 7:
  639.     case 8:
  640. #ifdef ELBERETH
  641.         if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) {
  642.         register struct obj *obj = uwep;    /* to be blessed */
  643.         boolean already_exists, in_hand;
  644.  
  645.         HSee_invisible |= FROMOUTSIDE;
  646.         HFire_resistance |= FROMOUTSIDE;
  647.         HCold_resistance |= FROMOUTSIDE;
  648.         HPoison_resistance |= FROMOUTSIDE;
  649.         godvoice(u.ualign.type,NULL);
  650.  
  651.         switch(u.ualign.type) {
  652.         case A_LAWFUL:
  653.             u.uevent.uhand_of_elbereth = 1;
  654.             verbalize("I crown thee...      The Hand of Elbereth!");
  655.             if (obj && (obj->otyp == LONG_SWORD) && !obj->oartifact)
  656.             obj = oname(obj, artiname(ART_EXCALIBUR), 1);
  657.             break;
  658.         case A_NEUTRAL:
  659.             u.uevent.uhand_of_elbereth = 2;
  660.             verbalize("Thou shalt be my Envoy of Balance!");
  661.             if (uwep && uwep->oartifact == ART_VORPAL_BLADE) {
  662.             obj = uwep;    /* to be blessed and rustproofed */
  663.             Your("%s goes snicker-snack!", xname(obj));
  664.             obj->dknown = TRUE;
  665.             } else if (!exist_artifact(LONG_SWORD,
  666.                         artiname(ART_VORPAL_BLADE))) {
  667.                 obj = mksobj(LONG_SWORD, FALSE, FALSE);
  668.             obj = oname(obj, artiname(ART_VORPAL_BLADE), 0);
  669.                 pline("%s %s %s your %s!", Blind ? "Something" : "A",
  670.                   Blind ? "lands" : "sword appears",
  671.                   Levitation ? "beneath" : "at",
  672.                   makeplural(body_part(FOOT)));
  673.             obj->spe = 1;
  674.             dropy(obj);
  675.             }
  676.             break;
  677.         case A_CHAOTIC:
  678.             /* This does the same damage as Excalibur.
  679.              * Disadvantages: doesn't do bonuses to undead;
  680.              *   doesn't aid searching.
  681.              * Advantage: part of that bonus is a level drain.
  682.              * Disadvantage: player cannot start with a +5 weapon and
  683.              * turn it into a Stormbringer.
  684.              * Advantage: they don't need to already have a sword of
  685.              *   the right type to get it...
  686.              * However, if Stormbringer already exists in the game, an
  687.              * ordinary good broadsword is given and the messages are
  688.              * a bit different.
  689.              */
  690.             u.uevent.uhand_of_elbereth = 3;
  691.             in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER);
  692.             already_exists = exist_artifact(RUNESWORD,
  693.                         artiname(ART_STORMBRINGER));
  694.             verbalize("Thou art chosen to %s for My Glory!",
  695.                   already_exists && !in_hand ?
  696.                   "take lives" : "steal souls");
  697.             if (in_hand) {
  698.             obj = uwep;    /* to be blessed and rustproofed */
  699.             } else if (!already_exists) {
  700.                 obj = mksobj(RUNESWORD, FALSE, FALSE);
  701.             obj = oname(obj, artiname(ART_STORMBRINGER), 0);
  702.                 pline("%s %s %s your %s!", Blind ? "Something" :
  703.                   An(Hallucination ? hcolor() : Black),
  704.                   Blind ? "lands" : "sword appears",
  705.                   Levitation ? "beneath" : "at",
  706.                   makeplural(body_part(FOOT)));
  707.             obj->spe = 1;
  708.             dropy(obj);
  709.             }
  710.             break;
  711.         default:
  712.             obj = 0;    /* lint */
  713.             break;
  714.         }
  715.         /* enhance weapon regardless of alignment or artifact status */
  716.         if (obj && obj->oclass == WEAPON_CLASS) {
  717.             bless(obj);
  718.             obj->oeroded = 0;
  719.             obj->oerodeproof = TRUE;
  720.             obj->bknown = obj->rknown = TRUE;
  721.             if (obj->spe < 1) obj->spe = 1;
  722.         } else    /* opportunity knocked, but there was nobody home... */
  723.             You("feel unworthy.");
  724.         break;
  725.         }
  726. #endif
  727.  
  728.     case 6:    pline ("An object appears at your %s!",
  729.                makeplural(body_part(FOOT)));
  730.         bless(mkobj_at(SPBOOK_CLASS, u.ux, u.uy, TRUE));
  731.         break;
  732.  
  733.     default:    impossible("Confused deity!");
  734.         break;
  735.     }
  736.     u.ublesscnt = rnz(350);
  737. #ifndef ELBERETH
  738.     u.ublesscnt += (u.uevent.udemigod * rnz(1000));
  739. #else
  740.     u.ublesscnt += ((u.uevent.udemigod + u.uevent.uhand_of_elbereth)
  741.                             * rnz(1000));
  742. #endif
  743.     return;
  744. }
  745.  
  746. /* either blesses or curses water on the altar,
  747.  * returns true if it found any water here.
  748.  */
  749. static boolean
  750. water_prayer(bless_water)
  751.     boolean bless_water;
  752. {
  753.     register struct obj* otmp;
  754.     register long changed = 0;
  755.     boolean other = FALSE;
  756.  
  757.     for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
  758.     /* turn water into (un)holy water */
  759.     if (otmp->otyp == POT_WATER) {
  760.         otmp->blessed = bless_water;
  761.         otmp->cursed = !bless_water;
  762.         otmp->bknown = !Blind;
  763.         changed += otmp->quan;
  764.     } else if(otmp->oclass == POTION_CLASS)
  765.         other = TRUE;
  766.     }
  767.     if(!Blind && changed) {
  768.     pline("%s potion%s on the altar glow%s %s for a moment.",
  769.           ((other && changed > 1L) ? "Some of the" : (other ? "A" : "The")),
  770.           (changed > 1L ? "s" : ""), (changed > 1L ? "" : "s"),
  771.           (bless_water ? amber : Black));
  772.     }
  773.     return((boolean)(changed > 0L));
  774. }
  775.  
  776. static void
  777. godvoice(g_align, words)
  778.     aligntyp g_align;
  779.     const char *words;
  780. {
  781.     const char *quot = "";
  782.     if(words)
  783.     quot = "\"";
  784.     else
  785.     words = "";
  786.  
  787.     pline("The voice of %s %s: %s%s%s", align_gname(g_align),
  788.       godvoices[rn2(SIZE(godvoices))], quot, words, quot);
  789. }
  790.  
  791. static void
  792. gods_angry(g_align)
  793.     aligntyp g_align;
  794. {
  795.     godvoice(g_align, "Thou hast angered me.");
  796. }
  797.  
  798. /* The g_align god is upset with you. */
  799. static void
  800. gods_upset(g_align)
  801.     aligntyp g_align;
  802. {
  803.     if(g_align == u.ualign.type) u.ugangr++;
  804.     else if(u.ugangr) u.ugangr--;
  805.     angrygods(g_align);
  806. }
  807.  
  808. static NEARDATA const char sacrifice_types[] = { FOOD_CLASS, AMULET_CLASS, 0 };
  809.  
  810. static void
  811. consume_offering(otmp)
  812. register struct obj *otmp;
  813. {
  814.     if (Hallucination)
  815.     switch (rn2(3)) {
  816.         case 0:
  817.         Your("sacrifice sprouts wings and a propeller and roars away!");
  818.         break;
  819.         case 1:
  820.         Your("sacrifice puffs up, swelling bigger and bigger, and pops!");
  821.         break;
  822.         case 2:
  823.         Your("sacrifice collapses into a cloud of dancing particles and fades away!");
  824.         break;
  825.     }
  826.     else if (Blind && u.ualign.type == A_LAWFUL)
  827.     Your("sacrifice disappears!");
  828.     else Your("sacrifice is consumed in a %s!",
  829.           u.ualign.type == A_LAWFUL ? "flash of light" : "burst of flame");
  830.     if (carried(otmp)) useup(otmp);
  831.     else useupf(otmp);
  832.     exercise(A_WIS, TRUE);
  833. }
  834.  
  835. int
  836. dosacrifice()
  837. {
  838.     register struct obj *otmp;
  839.     int value = 0;
  840.     aligntyp altaralign = a_align(u.ux,u.uy);
  841.  
  842.     if (!on_altar()) {
  843.     You("are not standing on an altar.");
  844.     return 0;
  845.     }
  846.  
  847.     if (In_endgame(&u.uz)) {
  848.     if (!(otmp = getobj(sacrifice_types, "sacrifice"))) return 0;
  849.     } else
  850.     if (!(otmp = floorfood("sacrifice", 0))) return 0;
  851.  
  852.     /*
  853.       Was based on nutritional value and aging behavior (< 50 moves).
  854.       Sacrificing a food ration got you max luck instantly, making the
  855.       gods as easy to please as an angry dog!
  856.  
  857.       Now only accepts corpses, based on the games evaluation of their
  858.       toughness.  Human sacrifice, as well as sacrificing unicorns of
  859.       your alignment, is strongly discouraged.  (We can't tell whether
  860.       a pet corpse was tame, so you can still sacrifice it.)
  861.      */
  862.  
  863. #define MAXVALUE 24 /* Highest corpse value (besides Wiz) */
  864.  
  865.     if (otmp->otyp == CORPSE) {
  866.     register struct permonst *ptr = &mons[otmp->corpsenm];
  867.     extern int monstr[];
  868.  
  869.     if (otmp->corpsenm == PM_ACID_BLOB || (monstermoves <= otmp->age + 50))
  870.         value = monstr[otmp->corpsenm] + 1;
  871.     if (otmp->oeaten)
  872.         value = eaten_stat(value, otmp);
  873.  
  874.     if ((pl_character[0]=='E') ? is_elf(ptr) : is_human(ptr)) {
  875. #ifdef POLYSELF
  876.         if (is_demon(uasmon)) {
  877.         You("find the idea very satisfying.");
  878.         exercise(A_WIS, TRUE);
  879.         } else
  880. #endif
  881.         if (u.ualign.type != A_CHAOTIC) {
  882.             pline("You'll regret this infamous offense!");
  883.             exercise(A_WIS, FALSE);
  884.         }
  885.  
  886.         if (altaralign != A_CHAOTIC && altaralign != A_NONE) {
  887.         /* curse the lawful/neutral altar */
  888.         pline("The altar is stained with %sn blood.",
  889.               (pl_character[0]=='E') ? "elve" : "huma");
  890.         if(!Is_astralevel(&u.uz))
  891.             levl[u.ux][u.uy].altarmask = AM_CHAOTIC;
  892.         angry_priest();
  893.         } else {
  894.         register struct monst *dmon;
  895.         /* Human sacrifice on a chaotic or unaligned altar */
  896.         /* is equivalent to demon summoning */
  897.         if(u.ualign.type != A_CHAOTIC) {
  898.         pline("The blood floods the altar, which vanishes in %s cloud!",
  899.               an(Hallucination ? hcolor() : Black));
  900.             levl[u.ux][u.uy].typ = ROOM;
  901.             levl[u.ux][u.uy].altarmask = 0;
  902.             if(Invisible) newsym(u.ux, u.uy);
  903.         } else {
  904.             pline("The blood covers the altar!");
  905.             change_luck(2);
  906.         }
  907.         if ((dmon = makemon(&mons[dlord(altaralign)], u.ux, u.uy))) {
  908.             You("have summoned %s!", a_monnam(dmon));
  909.             if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp))
  910.             dmon->mpeaceful = TRUE;
  911.             You("are terrified, and unable to move.");
  912.             nomul(-3);
  913.         } else pline("The cloud dissipates.");
  914.         }
  915.  
  916.         if (u.ualign.type != A_CHAOTIC) {
  917.         adjalign(-5);
  918.         u.ugangr += 3;
  919.         (void) adjattrib(A_WIS, -1, TRUE);
  920.         if (!Inhell) angrygods(u.ualign.type);
  921.         change_luck(-5);
  922.         } else adjalign(5);
  923.         if (carried(otmp)) useup(otmp);
  924.         else useupf(otmp);
  925.         return(1);
  926.     } else if (is_undead(ptr)) { /* Not demons--no demon corpses */
  927.         if (u.ualign.type != A_CHAOTIC)
  928.         value += 1;
  929.     } else if (ptr->mlet == S_UNICORN) {
  930.         int unicalign = sgn(ptr->maligntyp);
  931.  
  932.         /* If same as altar, always a very bad action. */
  933.         if (unicalign == altaralign) {
  934.         pline("Such an action is an insult to %s!",
  935.               (unicalign == A_CHAOTIC)
  936.               ? "chaos" : unicalign ? "law" : "balance");
  937.         (void) adjattrib(A_WIS, -1, TRUE);
  938.         value = -5;
  939.         } else if (u.ualign.type == altaralign) {
  940.         /* If different from altar, and altar is same as yours, */
  941.         /* it's a very good action */
  942.         if (u.ualign.record < ALIGNLIM)
  943.             You("feel appropriately %s.", align_str(u.ualign.type));
  944.         else You("feel you are thoroughly on the right path.");
  945.         adjalign(5);
  946.         value += 3;
  947.         } else
  948.         /* If sacrificing unicorn of your alignment to altar not of */
  949.         /* your alignment, your god gets angry and it's a conversion */
  950.         if (unicalign == u.ualign.type) {
  951.             u.ualign.record = -1;
  952.             value = 1;
  953.         } else value += 3;
  954.     }
  955.     }
  956.  
  957.     if (otmp->otyp == AMULET_OF_YENDOR) {
  958.     if (!In_endgame(&u.uz)) {
  959.         if (Hallucination)
  960.             You("feel homesick.");
  961.         else
  962.             You("feel an urge to return to the surface.");
  963.         return 1;
  964.     } else {
  965.         /* The final Test.    Did you win? */
  966.         if(uamul == otmp) Amulet_off();
  967.         u.uevent.ascended = 1;
  968.         if(carried(otmp)) useup(otmp); /* well, it's gone now */
  969.         else useupf(otmp);
  970.         You("offer the Amulet of Yendor to %s...", a_gname());
  971.         if (u.ualign.type != altaralign) {
  972.         /* And the opposing team picks you up and
  973.            carries you off on their shoulders */
  974.         adjalign(-99);
  975.         pline("%s accepts your gift, and gains dominion over %s...",
  976.               a_gname(), u_gname());
  977.         pline("%s is enraged...", u_gname());
  978.         pline("Fortunately, %s permits you to live...", a_gname());
  979.         pline("A cloud of %s smoke surrounds you...",
  980.               Hallucination ? hcolor() : (const char *)"orange");
  981.         done(ESCAPED);
  982.         } else { /* super big win */
  983.         adjalign(10);
  984. pline("An invisible choir sings, and you are bathed in radiance...");
  985.         godvoice(altaralign, "Congratulations, mortal!");
  986.         display_nhwindow(WIN_MESSAGE, FALSE);
  987. verbalize("In return for thy service, I grant thee the gift of Immortality!");
  988.         You("ascend to the status of Demigod%s...",
  989.             flags.female ? "dess" : "");
  990.         done(ASCENDED);
  991.         }
  992.     }
  993.     }
  994.  
  995.     if (otmp->otyp == FAKE_AMULET_OF_YENDOR) {
  996.         if (flags.soundok)
  997.         You("hear a nearby thunderclap.");
  998.         if (!otmp->known) {
  999.         You("realize you have made a %s.",
  1000.             Hallucination ? "boo-boo" : "mistake");
  1001.         otmp->known = TRUE;
  1002.         change_luck(-1);
  1003.         return 1;
  1004.         } else {
  1005.         /* don't you dare try to fool the gods */
  1006.         change_luck(-3);
  1007.         adjalign(-1);
  1008.         u.ugangr += 3;
  1009.         value = -3;
  1010.         }
  1011.     }
  1012.  
  1013.     if (value == 0) {
  1014.     pline(nothing_happens);
  1015.     return (1);
  1016.     }
  1017.  
  1018.     if(Is_astralevel(&u.uz) && (altaralign != u.ualign.type)) {
  1019.     /*
  1020.      * REAL BAD NEWS!!! High altars cannot be converted.  Even an attempt
  1021.      * gets the god who owns it truely pissed off.
  1022.      */
  1023.     You("feel the air around you grow charged...");
  1024.     pline("Suddenly, you realize that %s has noticed you...", a_gname());
  1025.     godvoice(altaralign, "So, mortal!  You dare desecrate my High Temple!");
  1026.     /* Throw everything we have at the player */
  1027.     god_zaps_you(altaralign);
  1028.     } else if (value < 0) /* I don't think the gods are gonna like this... */
  1029.     gods_upset(altaralign);
  1030.     else {
  1031.     int saved_anger = u.ugangr;
  1032.     int saved_cnt = u.ublesscnt;
  1033.     int saved_luck = u.uluck;
  1034.  
  1035.     /* Sacrificing at an altar of a different alignment */
  1036.     if (u.ualign.type != altaralign) {
  1037.         /* Is this a conversion ? */
  1038.         if(ugod_is_angry()) {
  1039.         if(u.ualignbase[0] == u.ualignbase[1] &&
  1040.            altaralign != A_NONE) {
  1041.             You("have a strong feeling that %s is angry...", u_gname());
  1042.             consume_offering(otmp);
  1043.             pline("%s accepts your allegiance.", a_gname());
  1044.             You("have a sudden sense of a new direction.");
  1045.  
  1046.             /* The player wears a helm of opposite alignment? */
  1047.             if (uarmh && uarmh->otyp == HELM_OF_OPPOSITE_ALIGNMENT)
  1048.             u.ualignbase[0] = altaralign;
  1049.             else
  1050.             u.ualign.type = u.ualignbase[0] = altaralign;
  1051.             flags.botl = 1;
  1052.             /* Beware, Conversion is costly */
  1053.             change_luck(-3);
  1054.             u.ublesscnt += 300;
  1055.             adjalign((int)(u.ualignbase[1] * (ALIGNLIM / 2)));
  1056.         } else {
  1057.             pline("%s rejects your sacrifice!", a_gname());
  1058.             godvoice(altaralign, "Suffer, infidel!");
  1059.             adjalign(-5);
  1060.             u.ugangr += 3;
  1061.             (void) adjattrib(A_WIS, -2, TRUE);
  1062.             if (!Inhell) angrygods(u.ualign.type);
  1063.             change_luck(-5);
  1064.         }
  1065.         return(1);
  1066.         } else {
  1067.         consume_offering(otmp);
  1068.         You("sense a conflict between %s and %s.",
  1069.             u_gname(), a_gname());
  1070.         if (rn2(8 + (int)u.ulevel) > 5) {
  1071.             struct monst *pri;
  1072.             You("feel the power of %s increase.", u_gname());
  1073.             exercise(A_WIS, TRUE);
  1074.             change_luck(1);
  1075.             /* Yes, this is supposed to be &=, not |= */
  1076.             levl[u.ux][u.uy].altarmask &= AM_SHRINE;
  1077.             /* the following accommodates stupid compilers */
  1078.             levl[u.ux][u.uy].altarmask =
  1079.             levl[u.ux][u.uy].altarmask | (Align2amask(u.ualign.type));
  1080.             if (!Blind)
  1081.             pline("The altar glows %s.",
  1082.                   Hallucination ? hcolor() :
  1083.                   u.ualign.type == A_LAWFUL ? White :
  1084.                   u.ualign.type ? Black : (const char *)"gray");
  1085.  
  1086.             if(rnl((int)u.ulevel) > 6 && u.ualign.record > 0 &&
  1087.                rnd(u.ualign.record) > (3*ALIGNLIM)/4)
  1088.             summon_minion(altaralign, TRUE);
  1089.             /* anger priest; test handles bones files */
  1090.             if((pri = findpriest(temple_occupied(u.urooms))) &&
  1091.                !p_coaligned(pri))
  1092.             angry_priest();
  1093.         } else {
  1094.             pline("Unluckily, you feel the power of %s decrease.",
  1095.               u_gname());
  1096.             change_luck(-1);
  1097.             exercise(A_WIS, FALSE);
  1098.             if(rnl((int)u.ulevel) > 6 && u.ualign.record > 0 &&
  1099.                rnd(u.ualign.record) > (7*ALIGNLIM)/8)
  1100.             summon_minion(altaralign, TRUE);
  1101.         }
  1102.         return(1);
  1103.         }
  1104.     }
  1105.  
  1106.     consume_offering(otmp);
  1107.     /* OK, you get brownie points. */
  1108.     if(u.ugangr) {
  1109.         u.ugangr -=
  1110.         ((value * (u.ualign.type == A_CHAOTIC ? 2 : 3)) / MAXVALUE);
  1111.         if(u.ugangr < 0) u.ugangr = 0;
  1112.         if(u.ugangr != saved_anger) {
  1113.         if (u.ugangr) {
  1114.             pline("%s seems %s.", u_gname(),
  1115.               Hallucination ? "groovy" : "slightly mollified");
  1116.  
  1117.             if ((int)u.uluck < 0) change_luck(1);
  1118.         } else {
  1119.             pline("%s seems %s.", u_gname(), Hallucination ?
  1120.               "cosmic (not a new fact)" : "mollified");
  1121.  
  1122.             if ((int)u.uluck < 0) u.uluck = 0;
  1123.         }
  1124.         } else { /* not satisfied yet */
  1125.         if (Hallucination)
  1126.             pline("The gods seem tall.");
  1127.         else You("have a feeling of inadequacy.");
  1128.         }
  1129.     } else if(ugod_is_angry()) {
  1130.         if(value > MAXVALUE) value = MAXVALUE;
  1131.         if(value > -u.ualign.record) value = -u.ualign.record;
  1132.         adjalign(value);
  1133.         You("feel partially absolved.");
  1134.     } else if (u.ublesscnt > 0) {
  1135.         u.ublesscnt -=
  1136.         ((value * (u.ualign.type == A_CHAOTIC ? 500 : 300)) / MAXVALUE);
  1137.         if(u.ublesscnt < 0) u.ublesscnt = 0;
  1138.         if(u.ublesscnt != saved_cnt) {
  1139.         if (u.ublesscnt) {
  1140.             if (Hallucination)
  1141.             You("realize that the gods are not like you and I.");
  1142.             else
  1143.             You("have a hopeful feeling.");
  1144.             if ((int)u.uluck < 0) change_luck(1);
  1145.         } else {
  1146.             if (Hallucination)
  1147.             pline("Overall, there is a smell of fried onions.");
  1148.             else
  1149.             You("have a feeling of reconciliation.");
  1150.             if ((int)u.uluck < 0) u.uluck = 0;
  1151.         }
  1152.         }
  1153.     } else {
  1154.         int nartifacts = nartifact_exist();
  1155.  
  1156.         /* you were already in pretty good standing */
  1157.         /* The player can gain an artifact */
  1158.         /* The chance goes down as the number of artifacts goes up */
  1159.         if (u.ulevel > 2 && !rn2(10 + (2 * nartifacts * nartifacts))) {
  1160.         otmp = mk_artifact((struct obj *)0, a_align(u.ux,u.uy));
  1161.         if (otmp) {
  1162.             if (otmp->spe < 0) otmp->spe = 0;
  1163.             if (otmp->cursed) uncurse(otmp);
  1164.             dropy(otmp);
  1165.             pline("An object appears at your %s!",
  1166.               makeplural(body_part(FOOT)));
  1167.             godvoice(u.ualign.type, "Use my gift wisely!");
  1168.             u.ublesscnt = rnz(300 + (50 * nartifacts));
  1169.             exercise(A_WIS, TRUE);
  1170.             return(1);
  1171.         }
  1172.         }
  1173.         change_luck((value * LUCKMAX) / (MAXVALUE * 2));
  1174.         if (u.uluck != saved_luck) {
  1175.         if (Blind)
  1176.             You("think something brushed your %s.", body_part(FOOT));
  1177.         else You(Hallucination ?
  1178.             "see crabgrass at your %s.  A funny thing in a dungeon." :
  1179.             "glimpse a four-leaf clover at your %s.",
  1180.             makeplural(body_part(FOOT)));
  1181.         }
  1182.     }
  1183.     }
  1184.     return(1);
  1185. }
  1186.  
  1187. int
  1188. dopray()
  1189. {
  1190.     int alignment;
  1191.  
  1192.     p_aligntyp = on_altar() ? a_align(u.ux,u.uy) : u.ualign.type;
  1193.     p_trouble = in_trouble();
  1194.  
  1195. #ifdef POLYSELF
  1196.     if (is_demon(uasmon) && (p_aligntyp != A_CHAOTIC)) {
  1197.     pline("The very idea of praying to a %s god is repugnant to you.",
  1198.           p_aligntyp ? "lawful" : "neutral");
  1199.     return(0);
  1200.     }
  1201. #endif
  1202.  
  1203.     if (u.ualign.type && u.ualign.type == -p_aligntyp)
  1204.     alignment = -u.ualign.record;
  1205.     /* Opposite alignment altar */
  1206.     else if (u.ualign.type != p_aligntyp) alignment = u.ualign.record / 2;
  1207.     /* Different (but non-opposite) alignment altar */
  1208.     else alignment = u.ualign.record;
  1209.  
  1210.     You("begin praying to %s.", align_gname(p_aligntyp));
  1211.     if ((!p_trouble && (u.ublesscnt > 0)) ||
  1212.     ((p_trouble < 0) && (u.ublesscnt > 100)) || /* minor difficulties */
  1213.     ((p_trouble > 0) && (u.ublesscnt > 200))) /* big trouble */
  1214.     p_type = 0;
  1215.     else if ((int)Luck < 0 || u.ugangr || alignment < 0)
  1216.     p_type = 1;
  1217.     else /* alignment >= 0 */ {
  1218.     if(on_altar() && u.ualign.type != p_aligntyp)
  1219.         p_type = 2;
  1220.     else
  1221.         p_type = 3;
  1222.     }
  1223.  
  1224. #ifdef POLYSELF
  1225.     if (is_undead(uasmon) && !Inhell &&
  1226.     (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10))))
  1227.     p_type = -1;
  1228. #endif
  1229.  
  1230. #ifdef WIZARD
  1231.     if (wizard && p_type >= 0) {
  1232.     if (yn("Force the gods to be pleased?") == 'y') {
  1233.         u.ublesscnt = 0;
  1234.         if (u.uluck < 0) u.uluck = 0;
  1235.         if (u.ualign.record <= 0) u.ualign.record = 1;
  1236.         u.ugangr = 0;
  1237.         if(p_type < 2) p_type = 3;
  1238.     }
  1239.     }
  1240. #endif
  1241.     nomul(-3);
  1242.     nomovemsg = "You finish your prayer.";
  1243.     afternmv = prayer_done;
  1244.  
  1245.     if(p_type == 3 && !Inhell) {
  1246.     /* if you've been true to your god you can't die while you pray */
  1247.     if (!Blind)
  1248.         You("are surrounded by a shimmering light.");
  1249.     u.uinvulnerable = TRUE;
  1250.     }
  1251.  
  1252.     return(1);
  1253. }
  1254.  
  1255. STATIC_PTR int
  1256. prayer_done()        /* M. Stephenson (1.0.3b) */
  1257. {
  1258.     aligntyp alignment = p_aligntyp;
  1259.  
  1260. #ifdef POLYSELF
  1261.     if(p_type == -1) {
  1262.     godvoice(alignment,
  1263.          alignment == A_LAWFUL ?
  1264.          "Vile creature, thou durst call upon me?" :
  1265.          "Walk no more, perversion of nature!");
  1266.     You("feel like you are falling apart.");
  1267.     rehumanize();
  1268.     losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN);
  1269.     exercise(A_CON, FALSE);
  1270.     return(1);
  1271.     }
  1272. #endif
  1273.     if (Inhell) {
  1274.     pline("Since you are in Gehennom, %s won't help you.",
  1275.           align_gname(alignment));
  1276.     /* haltingly aligned is least likely to anger */
  1277.     if (u.ualign.record <= 0 || rnl(u.ualign.record))
  1278.         angrygods(u.ualign.type);
  1279.     return(0);
  1280.     }
  1281.  
  1282.     if (p_type == 0) {
  1283.     if(on_altar() && u.ualign.type != alignment)
  1284.         (void) water_prayer(FALSE);
  1285.     u.ublesscnt += rnz(250);
  1286.     change_luck(-3);
  1287.     gods_upset(u.ualign.type);
  1288.     } else if(p_type == 1) {
  1289.     if(on_altar() && u.ualign.type != alignment)
  1290.         (void) water_prayer(FALSE);
  1291.     angrygods(u.ualign.type);    /* naughty */
  1292.     } else if(p_type == 2) {
  1293.     if(water_prayer(FALSE)) {
  1294.         /* attempted water prayer on a non-coaligned altar */
  1295.         u.ublesscnt += rnz(250);
  1296.         change_luck(-3);
  1297.         gods_upset(u.ualign.type);
  1298.     } else pleased(alignment);
  1299.     } else {
  1300.     u.uinvulnerable = FALSE;
  1301.     /* coaligned */
  1302.     if(on_altar())
  1303.         (void) water_prayer(TRUE);
  1304.     pleased(alignment); /* nice */
  1305.     }
  1306.     return(1);
  1307. }
  1308.  
  1309. int
  1310. doturn()
  1311. {    /* Knights & Priest(esse)s only please */
  1312.  
  1313.     register struct monst *mtmp, *mtmp2;
  1314.     register int    xlev = 6;
  1315.  
  1316.     if((pl_character[0] != 'P') &&
  1317.        (pl_character[0] != 'K')) {
  1318.         /* Try to use turn undead spell. */
  1319.         if (objects[SPE_TURN_UNDEAD].oc_name_known) {
  1320.             register int sp_no;
  1321.             for (sp_no = 0; sp_no < MAXSPELL &&
  1322.              spl_book[sp_no].sp_id != NO_SPELL &&
  1323.              spl_book[sp_no].sp_id != SPE_TURN_UNDEAD; sp_no++);
  1324.  
  1325.             if (sp_no < MAXSPELL &&
  1326.             spl_book[sp_no].sp_id == SPE_TURN_UNDEAD)
  1327.                 return spelleffects(++sp_no, TRUE);
  1328.         }
  1329.  
  1330.         You("don't know how to turn undead!");
  1331.         return(0);
  1332.     }
  1333.     if (
  1334. #  ifdef POLYSELF
  1335.         (u.ualign.type != A_CHAOTIC &&
  1336.             (is_demon(uasmon) || is_undead(uasmon))) ||
  1337. #  endif
  1338.         u.ugangr > 6 /* "Die, mortal!" */) {
  1339.  
  1340.         pline("For some reason, %s seems to ignore you.", u_gname());
  1341.         aggravate();
  1342.         exercise(A_WIS, FALSE);
  1343.         return(0);
  1344.     }
  1345.  
  1346.     if (Inhell) {
  1347.         pline("Since you are in Gehennom, %s won't help you.", u_gname());
  1348.         aggravate();
  1349.         return(0);
  1350.     }
  1351.     pline("Calling upon %s, you chant an arcane formula.", u_gname());
  1352.     exercise(A_WIS, TRUE);
  1353.     for(mtmp = fmon; mtmp; mtmp = mtmp2) {
  1354.         mtmp2 = mtmp->nmon;
  1355.         if(cansee(mtmp->mx,mtmp->my)) {
  1356.         if(!mtmp->mpeaceful && (is_undead(mtmp->data) ||
  1357.            (is_demon(mtmp->data) && (u.ulevel > (MAXULEV/2))))) {
  1358.  
  1359.             if(Confusion) {
  1360.             pline("Unfortunately, your voice falters.");
  1361.             mtmp->mflee = mtmp->mfrozen = mtmp->msleep = FALSE;
  1362.             mtmp->mcanmove = TRUE;
  1363.             } else if (! resist(mtmp, '\0', 0, TELL)) {
  1364.             switch (mtmp->data->mlet) {
  1365.                 /* this is intentional, lichs are tougher
  1366.                    than zombies. */
  1367.             case S_LICH:    xlev += 2;
  1368.             case S_GHOST:   xlev += 2;
  1369.             case S_VAMPIRE: xlev += 2;
  1370.             case S_WRAITH:  xlev += 2;
  1371.             case S_MUMMY:   xlev += 2;
  1372.             case S_ZOMBIE:
  1373.                 mtmp->mflee = TRUE; /* at least */
  1374.                 if(u.ulevel >= xlev &&
  1375.                    !resist(mtmp, '\0', 0, NOTELL)) {
  1376.                 if(u.ualign.type == A_CHAOTIC) {
  1377.                     mtmp->mpeaceful = TRUE;
  1378.                 } else { /* damn them */
  1379.                     You("destroy %s!", mon_nam(mtmp));
  1380.                     mondied(mtmp);
  1381.                 }
  1382.                 }
  1383.                 break;
  1384.             default:    mtmp->mflee = TRUE;
  1385.                 break;
  1386.             }
  1387.             }
  1388.         }
  1389.         }
  1390.     }
  1391.     nomul(-5);
  1392.     return(1);
  1393. }
  1394.  
  1395. const char *
  1396. a_gname()
  1397. {
  1398.     return(a_gname_at(u.ux, u.uy));
  1399. }
  1400.  
  1401. const char *
  1402. a_gname_at(x,y)     /* returns the name of an altar's deity */
  1403. xchar x, y;
  1404. {
  1405.     if(!IS_ALTAR(levl[x][y].typ)) return((char *)0);
  1406.  
  1407.     return align_gname(a_align(x,y));
  1408. }
  1409.  
  1410. const char *
  1411. u_gname()  /* returns the name of the player's deity */
  1412. {
  1413.     return align_gname(u.ualign.type);
  1414. }
  1415.  
  1416. const char *
  1417. align_gname(alignment)
  1418.     register aligntyp alignment;
  1419. {
  1420.     register struct ghods *aghod;
  1421.  
  1422.     if(alignment == A_NONE) return(Moloch);
  1423.  
  1424.     for(aghod=gods; aghod->classlet; aghod++)
  1425.         if(aghod->classlet == pl_character[0])
  1426.         switch(alignment) {
  1427.         case A_CHAOTIC:    return(aghod->chaos);
  1428.         case A_NEUTRAL:    return(aghod->balance);
  1429.         case A_LAWFUL:    return(aghod->law);
  1430.         default: impossible("unknown alignment.");
  1431.              return("Balance");
  1432.         }
  1433.     impossible("unknown character's god?");
  1434.     return("someone");
  1435. }
  1436.  
  1437. void
  1438. altar_wrath(x, y)
  1439. register int x, y;
  1440. {
  1441.     aligntyp altaralign = a_align(x,y);
  1442.  
  1443.     if(!strcmp(align_gname(altaralign), u_gname())) {
  1444.     godvoice(altaralign, "How darest thou desecrate my altar!");
  1445.     (void) adjattrib(A_WIS, -1, FALSE);
  1446.     } else {
  1447.     pline("A voice (could it be %s?) whispers:",
  1448.           align_gname(altaralign));
  1449.     verbalize("Thou shalt pay, infidel!");
  1450.     change_luck(-1);
  1451.     }
  1452. }
  1453.  
  1454. /*pray.c*/
  1455.